/**
 * Created with IntelliJ IDEA
 * Description:
 * User: Administrator
 * Data: 2023 - 07 - 08
 * Time: 14:41
 */
class Solution2 {
    public int dayOfYear(String date) {
        String[] str = date.split("-");//也可以用字符串截取
        int year = Integer.parseInt(str[0]);
        int month = Integer.parseInt(str[1]);
        int day = Integer.parseInt(str[2]);
        int sum = 0;
        int[] arr = new int[]{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
        if(((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) {
            arr[2]++;
        }
        if(month > 1) {
            month -= 1;
            while(month >= 0) {//也可以用for循环
                sum += arr[month];
                month--;
            }
        }
        return sum + day;
    }
}
